<template>
    <v-btn icon :color="upStatus ? 'indigo': null" @click="toggleUp">
        <v-icon>mdi-thumb-up</v-icon>
        点赞
    </v-btn>
</template>

<script>
export default {
    data(){
        return {
            upStatus: false,
            actions:{
                type: 'Works',
                object: '',
                name: 'upVote'
            },
        }
    },
    props: {
      object: {
        type: String,
        required: true
      },
    },
    methods: {
      
        async getUpStatus(){
            if(this.$axios.defaults.headers.common.Authorization){
                this.actions.object = this.object
                const res = await this.$axios.$get('actions/status', {
                    params: this.actions
                })
                this.upStatus = res.status
            }
        },
      
        async toggleUp(){
            if(this.$axios.defaults.headers.common.Authorization){
                this.actions.object = this.object
                const res = await this.$axios.$post('actions/toggle', this.actions)
                this.upStatus = res.status
            }else{
                this.$toast.error('请先登录')
            }
        }
    },
    mounted(){
        this.getUpStatus()
    }

}
</script>

<style>

</style>